<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>首页轮播</title>
  <script src="js/axios.js"></script>
  <style>
    #banner{
      width: 800px;
      height: 300px;
      margin: 100px auto;
      position: relative;
      transition: 2s all linear;
      border:1px solid gray;
      box-shadow: 0 0 30px gray;
    }
    #banner li {
      position: absolute;
      width: 800px;
      height: 800px;
      z-index: 1;
      transition: 2s all linear;
    }
    #banner li img {
      width: 800px;
      height: 300px;
      transition: 2s all linear;
    }
  </style>
</head>
<body>
  <h1>"首页轮播"</h1>

  <ul id="banner">
    <li>
      <img src="" alt="">
    </li>



  </ul>

  <script>
         getBannerList()
    function getBannerList(){
        axios.get('/mg/api2Get').then((res)=>{
            console.log(res);
        let html = '';
        res.data.forEach(v=>{
            html+=`
            <li class = "listBanner">
      <img src="../${v}" alt="">
    </li>`
        })
        banner.innerHTML = html;
      return  res.data.length;
      }).then((ll)=>{
        let listBanner = document.querySelectorAll('.listBanner');
        console.log(ll);
        let star = 0;
        let delStar = 10;
        if(ll>1){
          setInterval(function(){
            console.log(star);
             star+1 === ll?star=0:star;
             //Z-index 的最大值是 2147483647。这个值是 32 位的整数，所以理论上最大值是 2147483647。 后续优化
            listBanner[star++].style.zIndex = delStar++;
            // if(star>=1){
            //   listBanner[star-1].style.zIndex = "1";
            // }
        },2000)
        }else{
          console.log('只有一张图');
        }

      })
        
    }




  </script>
</body>
</html>
